package com.example.lt.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author 小涛Tao
 * @Date: 2024/06/04/19:58
 * version 1.0 注释：实现 MetaObjectHandler 接口 ，并且加入到 spring 容器中，这样mybatis-plus的自动填充功能才会生效
 **/
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("gmtCreated", new Date(), metaObject);
        this.setFieldValByName("gmtUpdated", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("gmtUpdated", new Date(), metaObject);
    }
}
